package com.spider;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

import com.spider.base.BaseResult;
import com.spider.base.BaseTask;
import com.spider.exception.ExecuterServiceIsNullException;
import com.spider.execute.timeExecute.TimerExecute;
import com.spider.task.ServiceResult;
import com.spider.task.ServiceTask;
import com.spider.task.timerTask.StartSpiderTask;
import com.spider.util.ExecuteServiceType;


public class Start {

	public static void main(String[] args) throws InterruptedException, ExecutionException{
//		getCollection();
		
		timeTask();
	}
	
	public static void getCollection(){
		long start = System.currentTimeMillis();
		ServiceTask<ServiceResult> t = null;
		List<BaseTask<ServiceResult>> list = new ArrayList<BaseTask<ServiceResult>>(); 
		for(int i = 0; i < 1000; i++){
			t =  new ServiceTask<ServiceResult>();
			list.add(t);
		}
		try {
			List<ServiceResult>  re =  ServiceTask.startTaskCollection(list,ExecuteServiceType.FIXED_THREAD_POOL);
			for(ServiceResult r : re){
				System.out.println(r.getName());
			}
		} catch (ExecutionException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecuterServiceIsNullException e) {
			e.printStackTrace();
		}
		
		System.out.println("系统耗时 ： " +(System.currentTimeMillis() - start));
	}
	
	/*** 启动  主线程 读取 base_url 中的所有的 url
	 */
	public static void timeTask(){
		StartSpiderTask start = new StartSpiderTask();
		TimerExecute.executeTimer(start, 3,2);
	}
	
}
